#!/bin/bash

# Props Management Demo Runner
# Multi-module version

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${BLUE}🚀 Starting Props Management Demo...${NC}"
echo "======================================"

# Check Java version
echo -e "${GREEN}✅ Java version:${NC} $(java -version 2>&1 | head -n 1)"

# Check Maven version
echo -e "${GREEN}✅ Maven version:${NC} $(mvn -version 2>&1 | head -n 1)"

# Clean and compile all modules
echo -e "${BLUE}📦 Building all modules...${NC}"
mvn clean compile -q
if [ $? -eq 0 ]; then
    echo -e "${GREEN}✅ Build successful!${NC}"
else
    echo -e "${RED}❌ Build failed!${NC}"
    exit 1
fi

# Install starter module to local repository
echo -e "${BLUE}📦 Installing starter module...${NC}"
mvn install -pl props-starter -q
if [ $? -eq 0 ]; then
    echo -e "${GREEN}✅ Starter module installed!${NC}"
else
    echo -e "${RED}❌ Starter module installation failed!${NC}"
    exit 1
fi

# Start demo application
echo -e "${BLUE}🎯 Starting demo application...${NC}"
echo "==============================="
echo -e "${GREEN}📱 Management Interface: http://localhost:8080/props-management${NC}"
echo -e "${GREEN}🔧 Demo API Endpoints:${NC}"
echo -e "   - http://localhost:8080/demo/config"
echo -e "   - http://localhost:8080/demo/health"
echo -e "   - http://localhost:8080/demo/info"
echo "==============================="

# Run demo module
cd props-demo
mvn spring-boot:run -Dspring-boot.run.profiles=demo -q 